package com.fucai.common.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Description: Swagger可视化接口文档配置
 * @Author: zhuchi
 * @CreateDate: 2020/6/17 15:40
 * @Version: 1.0
 */
@Configuration
@EnableOpenApi
//@EnableSwagger2 //开启swagger2
//@ConditionalOnProperty(prefix = "mconfig", name = "swagger-ui-open", havingValue = "true")
public class SwaggerConfig {

    @Bean
    public Docket createApi(){
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo()).enable(true)
                // 允许忽略预定义的响应消息默认值
                .useDefaultResponseMessages(false)
                .select()
                /*
                 * 通过apis方法，basePackage可以根据包路径来生成特定类的API
                 * any方法是默认所有都有效，
                 * none方法都无效；
                 * withClassAnnotation根据类注解，withMethodAnnotation是根据方法注解；一般我们用的是 basePackage方法
                 */
                .apis(RequestHandlerSelectors.basePackage("com.fucai.controller"))
                /*
                 * 根据请求路径的paths方法
                 *  1.ant匹配路径
                 *  2.any是匹配任意路径
                 *  3.none是都不匹配
                 *  4.regex是正则匹配
                 */
                .paths(PathSelectors.any())
                .build()
                .groupName("福彩");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API文档")
                .description("API文档")
                .version("1.0")
                .license("Apache 2.0")
                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
                .build();
    }

}
